using System;

namespace DynamicConfigurationManager.ConfigMapAttributes
{
    /// <summary>
    /// EnvironmentVariable matches to any environment varial and value; e.g. environmentVariable="environment=INIT".
    /// </summary>
    internal class EnvironmentVariable : IConfigMapAttribute
    {
        public bool Execute( string configMapAttribute )
        {
            // Create an array of items split by '=' character, don't forget to trim the spaces.
            var envandvalue = configMapAttribute.Split( '=' );
            if( envandvalue.Length < 2 )
            {
                return false;
            }

            var env = Environment.GetEnvironmentVariable( envandvalue[0].Trim() );
            return !string.IsNullOrWhiteSpace( env ) && env.Equals( envandvalue[1].Trim(), StringComparison.InvariantCultureIgnoreCase );
        }
    }
}